package edu.utexas.mapreduce;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class InputSplitterRecursive implements InputSplitter {

	private InputSplitter fileSplitter;
	
	InputSplitterRecursive(InputSplitter fileSplitter) {
		this.fileSplitter = fileSplitter;
	}
	
	public List<InputBlock> splitInput(File inputFile) {
		
		// skip hidden files
		if (inputFile.isHidden()) {
			return new ArrayList<InputBlock>();
		}
		
		// If a directory, use recursively traverse the directory
		if (inputFile.isDirectory()) {
			List<InputBlock> list = new ArrayList<InputBlock>();
			for (File file: inputFile.listFiles()) {
				list.addAll(splitInput(file));
			}
			return list;
		}
		
		if (inputFile.isFile()) {
			return fileSplitter.splitInput(inputFile);
		}
		
		return new ArrayList<InputBlock>();
	}
}
